package et.six.eta.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import et.six.eta.Ban.FoodList;
import et.six.eta.R;

public class ListAdapter extends BaseAdapter{
    List<FoodList> lists;
    Context context;
    LayoutInflater layoutInflater;

    public ListAdapter(List<FoodList> lists, Context context) {
        this.lists = lists;
        this.context = context;
       layoutInflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView==null){
            convertView = layoutInflater.inflate(R.layout.zhujiemian_main_item, null);
            vh = new ViewHolder();
            vh.food_Img =  convertView.findViewById(R.id.food_Img);
            vh.food_name =  convertView.findViewById(R.id.food_name);
            vh.food_Price =  convertView.findViewById(R.id.food_Price);
            vh.food_Price.setTextColor(Color.parseColor("#DC143C"));
            convertView.setTag(vh);
        }else{
            vh= (ViewHolder) convertView.getTag();
        }
        FoodList foodList=lists.get(position);
        Glide.with(convertView).load(foodList.getFood_Img()).into(vh.food_Img);
        vh.food_name.setText(foodList.getFood_name());
        vh.food_Price.setText(foodList.getFood_Price());
      return convertView;

    }
    static class ViewHolder {
        //表名 FoodList
        //food_Img 图片
        //food_name 名称
        //food_Price 价格
        //food_Detail 详情
        public ImageView food_Img;
        public TextView food_name;
        public TextView food_Price;
    }

}
